<?php

class orderBean 
{
    function orderBean()
    {
    }
   
   	function getECurrency($db){
    	$sql = sprintf("select * from %s", TBL_E_CURRENCY);
    	$res = $db->get_results($sql);
    	return $res;
    }
   
   function getSrcECurrency($db){
    	$sql = sprintf("select * from %s", TBL_BANK_LIST);
    	$res = $db->get_results($sql);
    	return $res;
    }
   
    /*
     * Get all buy E-currency Paging
     */
    function countBuyEcurrency($db){
    	$sql = "SELECT COUNT(b.buy_order_id) as total FROM ".TBL_BUY_ECURRENCY." b ";
    	$res = $db->get_row($sql);
    	
    	return $res->total;
    }
	
	function getBuyEcurrencyShare($db,$maxview,$path)
	{
		$page = isset ( $_GET[$path] ) ? intval ( $_GET[$path] ) : 1;
		$rows_per_page= $maxview;
		$page_start = ( $page - 1 ) * $rows_per_page;
		$page_end = $page * $rows_per_page;
	
		$strSQL = "SELECT b.*,s.bank_name,e.ecurrency_name FROM ".TBL_BUY_ECURRENCY." b ".
					" LEFT JOIN ".TBL_BANK_LIST." s ON b.buy_src_ecurrency = s.bank_id ".
					" LEFT JOIN ".TBL_E_CURRENCY." e ON b.buy_dst_ecurrency = e.id ".
					" ORDER BY b.buy_order_id ASC LIMIT $page_start, $rows_per_page";
		$res = $db->get_results($strSQL);
		return $res;
	}
    
	/*
     * Get all sell E-currency Paging
     */
    function countSellEcurrency($db){
    	$sql = "SELECT COUNT(s.sell_order_id) as total FROM ".TBL_SELL_ECURRENCY." s ";
    	$res = $db->get_row($sql);
    	
    	return $res->total;
    }
	
	function getSellEcurrencyShare($db,$maxview,$path)
	{
		$page = isset ( $_GET[$path] ) ? intval ( $_GET[$path] ) : 1;
		$rows_per_page= $maxview;
		$page_start = ( $page - 1 ) * $rows_per_page;
		$page_end = $page * $rows_per_page;
	
		$strSQL = "SELECT s.*,b.bank_name,e.ecurrency_name FROM ".TBL_SELL_ECURRENCY." s ".
					" LEFT JOIN ".TBL_BANK_LIST." b ON s.sell_src_ecurrency = b.bank_id ".
					" LEFT JOIN ".TBL_E_CURRENCY." e ON s.sell_dst_ecurrency = e.id ".
					" ORDER BY s.sell_order_id ASC LIMIT $page_start, $rows_per_page";
		$res = $db->get_results($strSQL);
		return $res;
	}
	/*
     * Get all Exchange E-currency Paging
     */
   	
	function countExEcurrency($db){
    	$sql = "SELECT COUNT(e.exchange_id) as total FROM ".TBL_EXCHANGE_ORDERS." e ";
    	$res = $db->get_row($sql);
    	
    	return $res->total;
    }
	
	function getExEcurrencyShare($db,$maxview,$path)
	{
		$page = isset ( $_GET[$path] ) ? intval ( $_GET[$path] ) : 1;
		$rows_per_page= $maxview;
		$page_start = ( $page - 1 ) * $rows_per_page;
		$page_end = $page * $rows_per_page;
	
		$strSQL = "SELECT e.*,s.ecurrency_name as ecurrency_name_spend,f.ecurrency_name as ecurrency_name_receive FROM ".TBL_EXCHANGE_ORDERS." e ".
					" LEFT JOIN ".TBL_E_CURRENCY." s ON e.spend_ecurrency = s.id ".
					" LEFT JOIN ".TBL_E_CURRENCY." f ON e.receive_ecurrency = f.id ".
					" ORDER BY e.exchange_id  ASC LIMIT $page_start, $rows_per_page";
		$res = $db->get_results($strSQL);
		return $res;
	}
	
	

}
?>